package threading;

/**
 * @author 徐志荣
 * @date 2023/3/16 8:30
 */
public class ThreadDemo9 {
    public static boolean isQuit = false;
    public static void main(String[] args) {
       // boolean isQuit = false;
        Thread thread = new Thread(() -> {
           while (!isQuit){
               System.out.println("hello t");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
            System.out.println("t 线程终止");
        });

        thread.start();

        //在主线程中,修改isQuit
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isQuit = true;

        /*  hello t
            hello t
            hello t
            t 线程终止
            */
    }
}
